class Solution {
    public int maxProfit(int[] prices) {
        int len = prices.length;
        if(0 == len||null == prices ) {
            return 0;
        }
        int max = 0;
        int min = Integer.MAX_VALUE;
        for(int i = 0;i<len;i++) {
            if(prices[i] < min) {
                min = prices[i];
            }else if(prices[i] > min && prices[i] - min > max) {
                 max = prices[i] - min;
            }
        }
        return max;
    }
}